extends Node2D

# 效果类型
enum EffectType {
	NONE,
	SANDSTORM,
	OASIS,
	RAIN,
	FOG,
	MUSHROOM,
	BLIZZARD,
	AVALANCHE,
	ICE_PATCH
}

# 效果属性
@export var effect_type: EffectType = EffectType.OASIS
@export var duration: float = 20.0
@export var healing_amount: int = 5

# 计时器
var time_alive: float = 0.0
var heal_timer: float = 0.0

# 玩家引用
var player = null

func _ready():
	# 设置初始外观
	$Sprite2D.texture = load("res://asset/effects/oasis.png")
	$Sprite2D.scale = Vector2(2.0, 2.0)
	
	# 获取玩家引用
	player = get_tree().get_first_node_in_group("player")
	
	# 创建区域
	$Area2D/CollisionShape2D.shape.radius = 100.0

func _process(delta):
	# 更新生命周期
	time_alive += delta
	
	# 处理治疗逻辑
	heal_timer += delta
	if heal_timer >= 1.0:  # 每秒治疗一次
		heal_timer = 0.0
		heal_player()
	
	# 到达最大存活时间后消失
	if time_alive >= duration:
		queue_free()

func heal_player():
	# 检查玩家是否在绿洲范围内
	if player and is_instance_valid(player) and $Area2D.overlaps_body(player):
		# 治疗玩家
		if player.has_method("heal"):
			player.heal(healing_amount)
			
			# 创建治疗效果
			var heal_effect = preload("res://HealEffect.tscn").instantiate()
			get_tree().get_root().add_child(heal_effect)
			heal_effect.global_position = player.global_position
